# -*- coding: utf-8 -*-
"""
Created on Thu Jul 31 08:24:08 2025

@author: pc
"""

import struct

name = 'z'

#手工转换float单精度数据
def binary_exponent(binary_str_1):
    expontent = int(binary_str_1, 2) -127
    return expontent

def binary_fraction_to_decimal(binary_str):
    decimal_fraction = 0
    for i, bit in enumerate(binary_str, 1):
        decimal_fraction += int(bit) * (2 ** -i)
    return decimal_fraction

with open(name+'_location_binary_data.txt','r') as file:
    binary_code = file.read()

binary_code = binary_code.replace(' ', '')

size = len(binary_code)
x_location_data = []

for i in range(1,int(size/32)+1):
    verify = binary_code [(32*(i-1)):(32*i)]
    data_exponent = binary_exponent(verify[25:32]+verify[16])
    data_fraction = binary_fraction_to_decimal(verify[17:24]+verify[8:16]+verify[0:8])
    
    num_value = (-1)**(int(verify[24]))*2**(data_exponent)*(1+data_fraction)
    x_location_data.append(num_value)

x_location_max = max(x_location_data)
x_location_min = min(x_location_data)

with open(name+'_location_data.txt','w') as f:
    for i in range(0,len(x_location_data)):
        f.write(str(x_location_data[i]))
        f.write('\n')
        
f.close()




